package com.bleeth.fx.component;

import com.bleeth.fx.helper.SStyleHelper;
import com.bleeth.fx.helper.ThemeTypeEnum;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import lombok.Builder;


/**
 * @author Sakura
 * @version 1.0
 * @date 2021-11-13 22:17
 **/
@Builder
public class MTag {

    @Builder.Default
    private String type = ThemeTypeEnum.PRIMARY_COLOR.getName();

    private boolean closable;

    private String color;

    private String text;


    private EventHandler closeEvent;

    private EventHandler clickEvent;


    public HBox make() {
        HBox box = new HBox();
        box.setSpacing(5);
        box.setPrefHeight(30D);
        box.setPrefWidth(60D);
        box.setAlignment(Pos.CENTER);

        Label t = new Label(text);
        Region icon = MIcon.builder().size(15).icon("icon-close").color(ThemeTypeEnum.getMatched(type).getValue()).build().make();


        SStyleHelper.node(box)
                .addStyle("-fx-background-color", ThemeTypeEnum.getMatched(type).getValue() + "11")
                .addStyle("-fx-border-color", ThemeTypeEnum.getMatched(type).getValue() + "33")
                .addStyle("-fx-border-width", "1")
                .addStyle("-fx-border-radius", "5")
                .apply();

        SStyleHelper.node(t)
                .addStyle("-fx-text-fill", ThemeTypeEnum.getMatched(type).getValue())
                .addStyle("-fx-font-size", "10")
                .apply();

        SStyleHelper.node(icon)
                .addStyle("-fx-background-radius",7)
                .addStyle("-fx-background-color",ThemeTypeEnum.TRANSPARENT_FONT_COLOR.getValue())
                .addHoverStyle("-fx-background-color",ThemeTypeEnum.getMatched(type).getValue()+"99")
                .apply();


        box.getChildren().add(t);
        box.getChildren().add(icon);
        return box;
    }


}
